<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="google-site-verification" content="xBT4GhYoi5qRD5tr338pgPM5OWHHIDR6mNg1a3euekI" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="android mio4kon mio">
    <meta name="keyword"  content="">
    <link rel="shortcut icon" href="/img/favicon.ico">

    <title>
        
          Why use Kotlin &amp; Kotlin Use Case  - Mio4kon的博客 | Mio4kon&#39;s Blog
        
    </title>

    <link rel="canonical" href="http://mio4kon.com/2016/08/30/Why use Kotlin &amp; Kotlin Use Case  /">

    <!-- Bootstrap Core CSS -->
    <link rel="stylesheet" href="/css/bootstrap.min.css">

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/hux-blog.min.css">

    <!-- Pygments Highlight CSS -->
    <link rel="stylesheet" href="/css/highlight.css">

    <!-- Custom Fonts -->
    <!-- <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css"> -->
    <!-- Hux change font-awesome CDN to qiniu -->
    <link href="https://cdn.staticfile.org/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">


    <!-- Hux Delete, sad but pending in China
    <link href='http://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/
    css'>
    -->


    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- ga & ba script hoook -->
    <script></script>
</head>


<!-- hack iOS CSS :active style -->
<body ontouchstart="">

    <!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="/">Mio4kon</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <!-- Known Issue, found by Hux:
            <nav>'s height woule be hold on by its content.
            so, when navbar scale out, the <nav> will cover tags.
            also mask any touch event of tags, unfortunately.
        -->
        <div id="huxblog_navbar">
            <div class="navbar-collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/">Home</a>
                    </li>

                    

                        
                    

                        
                        <li>
                            <a href="/about/">About</a>
                        </li>
                        
                    

                        
                        <li>
                            <a href="/archives/">Archives</a>
                        </li>
                        
                    

                        
                        <li>
                            <a href="/tags/">Tags</a>
                        </li>
                        
                    
                    
                </ul>
            </div>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container -->
</nav>
<script>
    // Drop Bootstarp low-performance Navbar
    // Use customize navbar with high-quality material design animation
    // in high-perf jank-free CSS3 implementation
    var $body   = document.body;
    var $toggle = document.querySelector('.navbar-toggle');
    var $navbar = document.querySelector('#huxblog_navbar');
    var $collapse = document.querySelector('.navbar-collapse');

    $toggle.addEventListener('click', handleMagic)
    function handleMagic(e){
        if ($navbar.className.indexOf('in') > 0) {
        // CLOSE
            $navbar.className = " ";
            // wait until animation end.
            setTimeout(function(){
                // prevent frequently toggle
                if($navbar.className.indexOf('in') < 0) {
                    $collapse.style.height = "0px"
                }
            },400)
        }else{
        // OPEN
            $collapse.style.height = "auto"
            $navbar.className += " in";
        }
    }
</script>


    <!-- Main Content -->
    
<!-- Image to hack wechat -->
<!-- <img src="http://mio4kon.com/img/icon_wechat.png" width="0" height="0"> -->
<!-- <img src="{{ site.baseurl }}/{% if page.header-img %}{{ page.header-img }}{% else %}{{ site.header-img }}{% endif %}" width="0" height="0"> -->

<!-- Post Header -->
<style type="text/css">
    header.intro-header{
        background-image: url('/img/home-bg.jpg')
    }
</style>
<header class="intro-header" >
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <div class="tags">
                        
                          <a class="tag" href="/tags/#Kotlin" title="Kotlin">Kotlin</a>
                        
                    </div>
                    <h1>Why use Kotlin &amp; Kotlin Use Case </h1>
                    <h2 class="subheading">最先进的语言Kotlin</h2>
                    <span class="meta">
                        Posted by Mio4kon on
                        2016-08-30
                    </span>
                </div>
            </div>
        </div>
    </div>
</header>

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">

    <!-- Post Container -->
            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                post-container">

                <h1 id="为什么选择Kotlin而不是Scala"><a href="#为什么选择Kotlin而不是Scala" class="headerlink" title="为什么选择Kotlin而不是Scala"></a>为什么选择Kotlin而不是Scala</h1><p>Scala开源客户端:<br><a href="https://github.com/shadowsocks/shadowsocks-android/tree/master/src/main/scala/com/github/shadowsocks" target="_blank" rel="external">shadowsocks-android</a></p>
<blockquote>
<p>Kotlin 与 Scala 的方法大相径庭,那为什么选择Kotlin而不是Scala?</p>
</blockquote>
<ul>
<li>没有太多的学习曲线,现学现用.</li>
<li>与<code>Java</code>紧密结合.</li>
<li>相对于<code>Scala</code>库小很多(小于7000个方法数)</li>
<li>JetBrains家的东西,IDE完美支持.</li>
</ul>
<h1 id="Kotlin相对于Java的优势"><a href="#Kotlin相对于Java的优势" class="headerlink" title="Kotlin相对于Java的优势"></a>Kotlin相对于Java的优势</h1><a id="more"></a>
<h2 id="case-1-null问题"><a href="#case-1-null问题" class="headerlink" title="case 1 - null问题"></a>case 1 - null问题</h2><p>java经常会遇到空指针的问题,于是经常会遇到一个问题:<strong>这个对象会不会为空?</strong><br>这会导致:<strong>Android代码往往充斥着不必要的null检查和空指针的崩溃</strong></p>
<p><code>Kotlin</code>规定声明变量默认必须要初始化.</p>
<p><strong>编译器会报错:</strong></p>
<pre><code>var str : String =null   
</code></pre><p>如果的确开始没有初始值需要这么定义:  </p>
<pre><code>var str : String ?=null
</code></pre><p>在使用的时候:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div></pre></td><td class="code"><pre><div class="line">//确保str不可能为空</div><div class="line">str!!.length</div><div class="line">//安全执行</div><div class="line">str?.length</div><div class="line">//或者自己家加判断</div><div class="line">if(str!=null)&#123;</div><div class="line">   str.length</div><div class="line">&#125;</div><div class="line"></div><div class="line">//甚至可以在为空的时候设置默认值</div><div class="line">val len = str?.length ?: -1  //-1</div></pre></td></tr></table></figure>
<h2 id="case-2-扩展函数"><a href="#case-2-扩展函数" class="headerlink" title="case 2 - 扩展函数"></a>case 2 - 扩展函数</h2><p><strong>试想一下如果想拿到一个String的最后一个字符该怎么做?</strong>  </p>
<p>先不去考虑空字符串的情况下,用<code>java</code>:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">StringUtils</span> </span>&#123;</div><div class="line">        <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">char</span> <span class="title">last</span><span class="params">(String s)</span> </span>&#123;</div><div class="line">            <span class="keyword">return</span> s.charAt (s.length () - <span class="number">1</span>);</div><div class="line">        &#125;</div><div class="line"> &#125;</div><div class="line"> </div><div class="line"> StringUtils.last (<span class="string">"HaHa!"</span>);<span class="comment">//!</span></div></pre></td></tr></table></figure>
<p>如果用<code>Kotlin</code>的话,一切都可以回归于对象!</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">fun String.last(): Char &#123;</div><div class="line">    return this[length - 1]</div><div class="line">&#125;</div><div class="line"></div><div class="line">&quot;HaHa!&quot;.last() //!</div></pre></td></tr></table></figure>
<h2 id="case-3-Data-Classes"><a href="#case-3-Data-Classes" class="headerlink" title="case 3 - Data Classes"></a>case 3 - Data Classes</h2><p><strong>一句话就可以搞定JavaBean</strong></p>
<pre><code>data class Custom(val id: Long, val name: String)
</code></pre><p>需要内部做转换的话:</p>
<pre><code>data class Custom(val id: Long, val name: String) {
    val upName: String
        get() = name.toUpperCase()
}

val ct = Custom(1, &quot;mio4kon&quot;)
println(ct.upName)
</code></pre><p>还可以这样:</p>
<pre><code>val (id, name) = ct
</code></pre><p>甚至可以这样:</p>
<pre><code>val ct2=ct.copy(name = &quot;mio&quot;)
</code></pre><h2 id="case-4-运算符重载"><a href="#case-4-运算符重载" class="headerlink" title="case 4 - 运算符重载"></a>case 4 - 运算符重载</h2><p><a href="http://kotlinlang.org/docs/reference/operator-overloading.html" target="_blank" rel="external">http://kotlinlang.org/docs/reference/operator-overloading.html</a></p>
<p>具体例子:</p>
<p><a href="https://gist.github.com/mio4kon/a1e38de3b68d40fe7505399698257e90" target="_blank" rel="external">gist</a></p>
<p> <code>util.add(one,two)</code>  <code>one.add(two)</code></p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">data</span> <span class="class"><span class="keyword">class</span> <span class="title">Money</span></span>(<span class="keyword">val</span> currency: String, <span class="keyword">val</span> amount: <span class="built_in">Int</span>)</div><div class="line"></div><div class="line"></div><div class="line"><span class="keyword">operator</span> <span class="function"><span class="keyword">fun</span> Money.<span class="title">plus</span><span class="params">(other: <span class="type">Money</span>)</span></span>: Money &#123;</div><div class="line">    <span class="keyword">if</span> (currency != other.currency) &#123;</div><div class="line">        <span class="keyword">throw</span> IllegalArgumentException(<span class="string">"currency 不匹配!"</span>)</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">return</span> copy(amount = amount + other.amount)</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">fun</span> <span class="title">main</span><span class="params">(args: <span class="type">Array</span>&lt;<span class="type">String</span>&gt;)</span></span> &#123;</div><div class="line">    <span class="keyword">val</span> one = Money(<span class="string">"RMB"</span>, <span class="number">100</span>)</div><div class="line">    <span class="keyword">val</span> two = Money(<span class="string">"RMB"</span>, <span class="number">200</span>)</div><div class="line">    <span class="keyword">val</span> three = one + two</div><div class="line">    println(three)</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="case-5-高阶函数"><a href="#case-5-高阶函数" class="headerlink" title="case 5 - 高阶函数"></a>case 5 - 高阶函数</h2><blockquote>
<p>高阶函数是—参数或者返回值是函数</p>
</blockquote>
<p>例子:在<code>onCreate</code>获取View的高度:</p>
<p>在<code>java</code>中:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">mView.getViewTreeObserver().addOnGlobalLayoutListener(  </div><div class="line">        <span class="keyword">new</span> OnGlobalLayoutListener() &#123;  </div><div class="line">            <span class="meta">@Override</span>  </div><div class="line">            <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onGlobalLayout</span><span class="params">()</span> </span>&#123;  </div><div class="line">                                                                                                                                                                                                                                        </div><div class="line">               <span class="keyword">int</span> viewHeight = mView.getHeight();</div><div class="line">                getViewTreeObserver()  </div><div class="line">                        .removeGlobalOnLayoutListener(<span class="keyword">this</span>);  </div><div class="line">            &#125;  </div><div class="line">        &#125;);</div></pre></td></tr></table></figure>
<p>用<code>Kotlin</code>的话:</p>
<pre><code>mView.waitForLayout{
            //to do
        }
</code></pre><figure class="highlight kotlin"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">inline</span> <span class="function"><span class="keyword">fun</span> View.<span class="title">waitForLayout</span><span class="params">(<span class="keyword">crossinline</span> f: ()</span></span> -&gt; <span class="built_in">Unit</span>) = with(viewTreeObserver) &#123;</div><div class="line"></div><div class="line">    addOnGlobalLayoutListener(<span class="keyword">object</span> : ViewTreeObserver.OnGlobalLayoutListener &#123;</div><div class="line">        <span class="keyword">override</span> <span class="function"><span class="keyword">fun</span> <span class="title">onGlobalLayout</span><span class="params">()</span></span> &#123;</div><div class="line">            removeOnGlobalLayoutListener(<span class="keyword">this</span>)</div><div class="line">            f()</div><div class="line">        &#125;</div><div class="line">    &#125;)</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="case-6-委托"><a href="#case-6-委托" class="headerlink" title="case 6 - 委托"></a>case 6 - 委托</h2><p>用java来实现委托给另一个对象来处理的话:</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div></pre></td><td class="code"><pre><div class="line"><span class="class"><span class="keyword">interface</span> <span class="title">Base</span> </span>&#123;</div><div class="line">       <span class="function"><span class="keyword">void</span> <span class="title">println</span><span class="params">()</span></span>;</div><div class="line">   &#125;</div><div class="line"></div><div class="line">   <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">BaseImpl</span> <span class="keyword">implements</span> <span class="title">Base</span> </span>&#123;</div><div class="line">       <span class="keyword">private</span> <span class="keyword">int</span> x;</div><div class="line"></div><div class="line">       <span class="function"><span class="keyword">public</span> <span class="title">BaseImpl</span><span class="params">(<span class="keyword">int</span> x)</span> </span>&#123;</div><div class="line">           <span class="keyword">this</span>.x = x;</div><div class="line">       &#125;</div><div class="line"></div><div class="line">       <span class="meta">@Override</span></div><div class="line">       <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">println</span><span class="params">()</span> </span>&#123;</div><div class="line">           System.out.println (x);</div><div class="line">       &#125;</div><div class="line">   &#125;</div><div class="line"></div><div class="line"></div><div class="line">   <span class="comment">//class Derived(b: Base) : Base by b</span></div><div class="line">   <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">Derived</span> </span>&#123;</div><div class="line">       <span class="keyword">private</span> Base base;</div><div class="line"></div><div class="line">       <span class="function"><span class="keyword">public</span> <span class="title">Derived</span><span class="params">(Base base)</span> </span>&#123;</div><div class="line">           <span class="keyword">this</span>.base = base;</div><div class="line">       &#125;</div><div class="line"></div><div class="line">       <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">println</span><span class="params">()</span> </span>&#123;</div><div class="line">           base.println ();</div><div class="line">       &#125;</div><div class="line">   &#125;</div><div class="line"></div><div class="line">   <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</div><div class="line">       BaseImpl base = <span class="keyword">new</span> BaseImpl (<span class="number">100</span>);</div><div class="line">       <span class="keyword">new</span> Derived (base).println ();</div><div class="line">   &#125;</div></pre></td></tr></table></figure>
<p>Kotlin原生就支持它</p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"></div><div class="line"><span class="class"><span class="keyword">interface</span> <span class="title">Base</span> </span>&#123;</div><div class="line">    <span class="function"><span class="keyword">fun</span> <span class="title">println</span><span class="params">()</span></span></div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">BaseImpl</span></span>(<span class="keyword">var</span> x: <span class="built_in">Int</span>) : Base &#123;</div><div class="line">    <span class="keyword">override</span> <span class="function"><span class="keyword">fun</span> <span class="title">println</span><span class="params">()</span></span> &#123;</div><div class="line">        println(x)</div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="keyword">val</span> b =BaseImpl(<span class="number">100</span>)</div><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">Derived</span></span>() : Base <span class="keyword">by</span> b</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">fun</span> <span class="title">main</span><span class="params">(args: <span class="type">Array</span>&lt;<span class="type">String</span>&gt;)</span></span> &#123;</div><div class="line">    Derived().println()</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>b将会被储存在 Derived 的内部对象中,并且编译器会生成所有的用于转发给b的base的方法</p>
<p>Kotlin有一些标准的委托:Android中比较常用的是<code>lazy</code>:</p>
<pre><code>延迟执行:在第一用到的时候才执行
val toolbar by lazy { find&lt;Toolbar&gt;(R.id.toolbar) }
</code></pre><h2 id="case-7-接口默认方法"><a href="#case-7-接口默认方法" class="headerlink" title="case 7 - 接口默认方法"></a>case 7 - 接口默认方法</h2><p><strong>场景: 很多类实现了某一接口,接口如果需要增加功能,会影响老的代码.如何为了不影响老代码,同时又可以在新代码上增加新的功能?</strong></p>
<figure class="highlight kotlin"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line"></div><div class="line"><span class="class"><span class="keyword">interface</span> <span class="title">Lifecycle</span> </span>&#123;</div><div class="line">    <span class="function"><span class="keyword">fun</span> <span class="title">onStart</span><span class="params">()</span></span></div><div class="line">    <span class="function"><span class="keyword">fun</span> <span class="title">onDestroy</span><span class="params">()</span></span></div><div class="line">	</div><div class="line">	<span class="comment">//new</span></div><div class="line">    <span class="function"><span class="keyword">fun</span> <span class="title">onStop</span><span class="params">()</span></span>&#123;</div><div class="line">        println(<span class="string">"onstop"</span>)</div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="class"><span class="keyword">class</span> <span class="title">LifecycleObserver</span> : <span class="type">Lifecycle &#123;</span></span></div><div class="line">    <span class="keyword">override</span> <span class="function"><span class="keyword">fun</span> <span class="title">onStart</span><span class="params">()</span></span> &#123;</div><div class="line"></div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">override</span> <span class="function"><span class="keyword">fun</span> <span class="title">onDestroy</span><span class="params">()</span></span> &#123;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="case-8-强大的集合操作"><a href="#case-8-强大的集合操作" class="headerlink" title="case 8 - 强大的集合操作"></a>case 8 - 强大的集合操作</h2><p><a href="http://antonioleiva.com/collection-operations-kotlin/" target="_blank" rel="external">http://antonioleiva.com/collection-operations-kotlin/</a></p>
<h1 id="Android-实践"><a href="#Android-实践" class="headerlink" title="Android 实践"></a>Android 实践</h1><p><a href="https://github.com/mio4kon/Kotlin-Android-Practice" target="_blank" rel="external">https://github.com/mio4kon/Kotlin-Android-Practice</a></p>
<p><a href="https://github.com/antoniolg/Bandhook-Kotlin" target="_blank" rel="external">https://github.com/antoniolg/Bandhook-Kotlin</a></p>


                <hr>

                

                <ul class="pager">
                    
                        <li class="previous">
                            <a href="/2016/10/14/Atom之React Native配置/" data-toggle="tooltip" data-placement="top" title="React Native 开发工具之 Atom 配置">&larr; Previous Post</a>
                        </li>
                    
                    
                        <li class="next">
                            <a href="/2016/08/17/Kotlin for Android实践/" data-toggle="tooltip" data-placement="top" title="Kotlin for Android 实践">Next Post &rarr;</a>
                        </li>
                    
                </ul>

                

                
                <!-- disqus 评论框 start -->
                <div class="comment">
                    <div id="disqus_thread" class="disqus-thread"></div>
                </div>
                <!-- disqus 评论框 end -->
                

            </div>
    <!-- Side Catalog Container -->
        
            <div class="
                col-lg-2 col-lg-offset-0
                visible-lg-block
                sidebar-container
                catalog-container">
                <div class="side-catalog">
                    <hr class="hidden-sm hidden-xs">
                    <h5>
                        <a class="catalog-toggle" href="#">CATALOG</a>
                    </h5>
                    <ul class="catalog-body"></ul>
                </div>
            </div>
        

    <!-- Sidebar Container -->

            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                sidebar-container">

                <!-- Featured Tags -->
                
                <section>
                    <!-- no hr -->
                    <h5><a href="/tags/">FEATURED TAGS</a></h5>
                    <div class="tags">
                       
                          <a class="tag" href="/tags/#Kotlin" title="Kotlin">Kotlin</a>
                        
                    </div>
                </section>
                

                <!-- Friends Blog -->
                
                <hr>
                <h5>FRIENDS</h5>
                <ul class="list-inline">

                    
                        <li><a href="http://lrd.ele.me/" target="_blank">lrd ele&#39;s Blog</a></li>
                    
                </ul>
                
            </div>

        </div>
    </div>
</article>




<!-- disqus 公共JS代码 start (一个网页只需插入一次) -->
<script type="text/javascript">
    /* * * CONFIGURATION VARIABLES * * */
    var disqus_shortname = "hexo-theme-huxblog";
    var disqus_identifier = "http://mio4kon.com/2016/08/30/Why use Kotlin &amp; Kotlin Use Case  /";
    var disqus_url = "http://mio4kon.com/2016/08/30/Why use Kotlin &amp; Kotlin Use Case  /";

    (function() {
        var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
        dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
    })();
</script>
<!-- disqus 公共JS代码 end -->




<!-- async load function -->
<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>
<!-- anchor-js, Doc:http://bryanbraun.github.io/anchorjs/ -->
<script>
    async("https://cdn.bootcss.com/anchor-js/1.1.1/anchor.min.js",function(){
        anchors.options = {
          visible: 'always',
          placement: 'right',
          icon: '#'
        };
        anchors.add().remove('.intro-header h1').remove('.subheading').remove('.sidebar-container h5');
    })
</script>
<style>
    /* place left on bigger screen */
    @media all and (min-width: 800px) {
        .anchorjs-link{
            position: absolute;
            left: -0.75em;
            font-size: 1.1em;
            margin-top : -0.1em;
        }
    }
</style>



    <!-- Footer -->
    <!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <ul class="list-inline text-center">
                
                
                

                
                    <li>
                        <a target="_blank" href="http://weibo.com/u/3198010790">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-weibo fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                

                

                
                    <li>
                        <a target="_blank"  href="https://github.com/Mio4kon">
                            <span class="fa-stack fa-lg">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-github fa-stack-1x fa-inverse"></i>
                            </span>
                        </a>
                    </li>
                

                

                </ul>
                <p class="copyright text-muted">
                    Copyright &copy; Mio4kon 2019 
                    <br>
                    Theme by <a href="http://huangxuan.me">Hux</a> 
                    <span style="display: inline-block; margin: 0 5px;">
                        <i class="fa fa-heart"></i>
                    </span> 
                    Ported by <a href="http://blog.kaijun.rocks">Kaijun</a> | 
                    <iframe
                        style="margin-left: 2px; margin-bottom:-5px;"
                        frameborder="0" scrolling="0" width="91px" height="20px"
                        src="https://ghbtns.com/github-btn.html?user=kaijun&repo=hexo-theme-huxblog&type=star&count=true" >
                    </iframe>
                </p>
            </div>
        </div>
    </div>
</footer>

<!-- jQuery -->
<script src="/js/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="/js/bootstrap.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="/js/hux-blog.min.js"></script>


<!-- async load function -->
<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>

<!-- 
     Because of the native support for backtick-style fenced code blocks 
     right within the Markdown is landed in Github Pages, 
     From V1.6, There is no need for Highlight.js, 
     so Huxblog drops it officially.

     - https://github.com/blog/2100-github-pages-now-faster-and-simpler-with-jekyll-3-0  
     - https://help.github.com/articles/creating-and-highlighting-code-blocks/    
-->
<!--
    <script>
        async("http://cdn.bootcss.com/highlight.js/8.6/highlight.min.js", function(){
            hljs.initHighlightingOnLoad();
        })
    </script>
    <link href="http://cdn.bootcss.com/highlight.js/8.6/styles/github.min.css" rel="stylesheet">
-->


<!-- jquery.tagcloud.js -->
<script>
    // only load tagcloud.js in tag.html
    if($('#tag_cloud').length !== 0){
        async("http://mio4kon.com/js/jquery.tagcloud.js",function(){
            $.fn.tagcloud.defaults = {
                //size: {start: 1, end: 1, unit: 'em'},
                color: {start: '#bbbbee', end: '#0085a1'},
            };
            $('#tag_cloud a').tagcloud();
        })
    }
</script>

<!--fastClick.js -->
<script>
    async("https://cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js", function(){
        var $nav = document.querySelector("nav");
        if($nav) FastClick.attach($nav);
    })
</script>


<!-- Google Analytics -->




<!-- Baidu Tongji -->


<!-- Side Catalog -->

<script type="text/javascript">
    function generateCatalog (selector) {
        var P = $('div.post-container'),a,n,t,l,i,c;
        a = P.find('h1,h2,h3,h4,h5,h6');
        a.each(function () {
            n = $(this).prop('tagName').toLowerCase();
            i = "#"+$(this).prop('id');
            t = $(this).text();
            c = $('<a href="'+i+'" rel="nofollow">'+t+'</a>');
            l = $('<li class="'+n+'_nav"></li>').append(c);
            $(selector).append(l);
        });
        return true;    
    }

    generateCatalog(".catalog-body");

    // toggle side catalog
    $(".catalog-toggle").click((function(e){
        e.preventDefault();
        $('.side-catalog').toggleClass("fold")
    }))

    /*
     * Doc: https://github.com/davist11/jQuery-One-Page-Nav
     * Fork by Hux to support padding
     */
    async("/js/jquery.nav.js", function () {
        $('.catalog-body').onePageNav({
            currentClass: "active",
            changeHash: !1,
            easing: "swing",
            filter: "",
            scrollSpeed: 700,
            scrollOffset: 0,
            scrollThreshold: .2,
            begin: null,
            end: null,
            scrollChange: null,
            padding: 80
        });
    });
</script>





<!-- Image to hack wechat -->
<img src="http://mio4kon.com/img/icon_wechat.png" width="0" height="0" />
<!-- Migrate from head to bottom, no longer block render and still work -->

</body>

</html>
